package com.fr.report.io.core;

import com.fr.report.cellElement.Formula;
import com.fr.third.org.apache.poi.hssf.usermodel.HSSFCell;
import com.fr.third.org.apache.poi.hssf.usermodel.HSSFDateUtil;
import com.fr.third.org.apache.poi.hssf.util.HSSFColor;
import com.fr.util.Utils;
import java.awt.Color;
import java.io.PrintStream;
import java.util.Hashtable;
import java.util.Iterator;
import java.util.Set;

public class ExcelUtils
{
  public static final double AJUST_WIDTH = 34.741999999999997D;
  public static final double AJUST_HEIGHT = 15.207675329298683D;
  private static Hashtable colorHash = new Hashtable();
  private static Hashtable hssfColorIndexHash = HSSFColor.getIndexHash();
  public static final short EXCEL_COLUMN_WIDTH_FACTOR = 256;
  public static final int UNIT_OFFSET_LENGTH = 7;
  public static final int[] UNIT_OFFSET_MAP = { 0, 36, 73, 109, 146, 182, 219 };

  public static short transColor(int paramInt)
  {
    Object localObject = colorHash.get(String.valueOf(paramInt));
    if (localObject == null)
    {
      Color localColor = new Color(paramInt, true);
      int i = localColor.getRed();
      int j = localColor.getGreen();
      int k = localColor.getBlue();
      int l = 0;
      double d1 = 1.7976931348623157E+308D;
      Iterator localIterator = hssfColorIndexHash.keySet().iterator();
      do
      {
        int i1;
        double d2;
        while (true)
        {
          if (!(localIterator.hasNext()))
            break label182;
          Integer localInteger = (Integer)localIterator.next();
          i1 = localInteger.intValue();
          short[] arrayOfShort = ((HSSFColor)hssfColorIndexHash.get(localInteger)).getTriplet();
          d2 = Math.pow(i - arrayOfShort[0], 2.0D) + Math.pow(j - arrayOfShort[1], 2.0D) + Math.pow(k - arrayOfShort[2], 2.0D);
          if (d2 < d1)
            break;
        }
        d1 = d2;
        l = i1;
      }
      while (d1 != 0.0D);
      label182: colorHash.put(String.valueOf(paramInt), String.valueOf(l));
      return (short)l;
    }
    return Short.valueOf((String)localObject).shortValue();
  }

  public static short pixel2WidthUnits(int paramInt)
  {
    return (short)(int)Math.ceil(34.741999999999997D * paramInt);
  }

  public static int widthUnits2Pixel(short paramShort)
  {
    int i = paramShort / 256 * 7;
    int j = paramShort % 256;
    i += Math.round(j / 36.57143F);
    return i;
  }

  public static short printWidth2Design(short paramShort)
  {
    if (paramShort <= 0)
      return 0;
    paramShort = (short)(int)(paramShort * 0.75D);
    short s = (short)((paramShort + 30) / 70 * 4);
    int i = (short)((paramShort + 30) % 70);
    if ((i >= 0) && (i < 20))
      break label105:
    if ((i >= 20) && (i < 40))
      s = (short)(s + 1);
    else if ((i >= 40) && (i <= 50))
      s = (short)(s + 2);
    else if ((i > 50) && (i < 70))
      s = (short)(s + 3);
    label105: return (short)(paramShort - s);
  }

  public static short printWidth2Desing_2(short paramShort)
  {
    if (paramShort <= 0)
      return 0;
    paramShort = (short)(paramShort - paramShort / 30 * 2);
    return paramShort;
  }

  public static short designWidth2Print(short paramShort)
  {
    return paramShort;
  }

  public static void main(String[] paramArrayOfString)
  {
    System.out.println("236---->" + printWidth2Design(72));
  }

  public static Object getHSSFCellValue(HSSFCell paramHSSFCell)
  {
    Object localObject = null;
    if (paramHSSFCell.getCellType() == 1)
    {
      localObject = paramHSSFCell.getStringCellValue();
    }
    else if (paramHSSFCell.getCellType() == 0)
    {
      if (HSSFDateUtil.isCellDateFormatted(paramHSSFCell))
        return paramHSSFCell.getDateCellValue();
      localObject = Utils.string2Number(Utils.doubleToString(paramHSSFCell.getNumericCellValue()));
    }
    else if (paramHSSFCell.getCellType() == 4)
    {
      localObject = (paramHSSFCell.getBooleanCellValue()) ? Boolean.TRUE : Boolean.FALSE;
    }
    else if (paramHSSFCell.getCellType() == 2)
    {
      String str = paramHSSFCell.getCellFormula();
      localObject = new Formula(str);
    }
    else if (paramHSSFCell.getCellType() == 5)
    {
      localObject = "" + paramHSSFCell.getErrorCellValue();
    }
    else if (paramHSSFCell.getCellType() == 3)
    {
      localObject = "";
    }
    return localObject;
  }
}